package com.gali.leetcode.day20;

import java.util.Arrays;

/**
 * @Auther: gali
 * @Date: 2022-08-07 19:58
 * @Description:
 */
public class Solution {
    /**
     * 颜色分类----冒泡排序
     * @param nums
     */
    public void sortColors(int[] nums) {
        int index=nums.length- 1;
        int lastIndex=index;
        for (int i = 0; i < index; i++) {
            int currIndex=0;
            boolean changeCheck=false;
            for (int j = 0; j < lastIndex; j++) {
                if (nums[j]>nums[j+1]){
                    int temp=nums[j];
                    nums[j]=nums[j+1];
                    nums[j+1]=temp;
                    changeCheck=true;
                }
            }
            if (lastIndex==0){
                return;
            }
            if (changeCheck==false){
                return;
            }
            System.out.println(Arrays.toString(nums));
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int []nums={1,3,5,5,6,9,1,5,7,5};
        solution.sortColors(nums);
    }
}
